﻿using System.Collections.Generic;
using DataEntities;
using NUnit.Framework;
using Repositories.Repository;
using Repositories.UoW;

namespace TestRepositories
{
    [TestFixture]
    public class TestDistrictRepository : ITestRepository
    {
        private RepositoryFactory _repositoryFactory;
        private IDistrictRepository _repository;
        private District _district;

        [SetUp]
        public void SetUp()
        {
            _repositoryFactory=new RepositoryFactory();
            _repository = _repositoryFactory.GetDistrictRepository();
        }

        [TearDown]
        public void CleanUp()
        {
        }
        
        [Test]
        public void TestGet()
        {
            Assert.AreEqual(4,_repository.Get(4).Id);
        }

        [Test]
        public void TestGetList()
        {
            Assert.AreEqual(7,_repository.GetList().Count);
        }

        [Test]
        public void TestInsert()
        {
            Assert.AreEqual(1, _repository.Insert(new District("test")));
            Assert.AreEqual(1, _repository.Insert(new District("test1")));
            Assert.AreEqual(1, _repository.Insert(new District("test2")));
        }
        
        [Test]
        public void TestUpdate()
        {
            _district= _repository.Get(3);
            _district.Name = "TestUpdated";
            Assert.AreEqual(1,_repository.Update(_district));
        }

        [Test]
        [Ignore]
        public void TestDelete()
        {
            _district = new District(2,"Спартановка");
            Assert.AreEqual(1,_repository.Delete(_district));
        }

        [Test]
        public void TestEquals()
        {
            _district = new District(2,"Спартановка");
            Assert.AreEqual(_district,_repository.Get(2));
        }

        [Test]
        public void TestInsertList()
        {
            IList<District> list=new List<District>();
            list.Add(new District("1"));
            list.Add(new District("2"));
            list.Add(new District("3"));
            Assert.AreEqual(3, _repository.InsertList(list));
        }

        [Test]
        public void UpdateList()
        {
            IList<District> list=new List<District>();
            list.Add(_repository.Get(1));
            list.Add(_repository.Get(3));
            list.Add(_repository.Get(5));
            list.Add(_repository.Get(6));

            foreach (District item in list)
            {
                item.Name += "UpdatedList";
            }

            Assert.AreEqual(4,_repository.UpdateList(list));
        }

        [Test]
        [Ignore]
        public void TestDeleteList()
        {
            IList<District> list = new List<District>();
            list.Add(_repository.Get(1));
            list.Add(_repository.Get(3));
            list.Add(_repository.Get(5));
            list.Add(_repository.Get(6));
            Assert.AreEqual(4,_repository.DeleteList(list));            
        }

        [Test]
        public void TestGetChildDogovorList()
        {
            Assert.AreEqual(152,_repository.Get(1).DogovorList.Count);
        }
    }
}